package com.yiji.fintech.musfinance.facadeimpl.online;

import com.acooly.core.utils.enums.ResultStatus;
import com.alibaba.dubbo.config.annotation.Service;
import com.yiji.fintech.musfinance.center.base.order.OrderFacade;
import com.yiji.fintech.musfinance.center.base.result.ResultFacade;
import com.yiji.fintech.musfinance.center.deposit.api.OnlineFacade;
import com.yiji.fintech.musfinance.center.deposit.order.facade.*;
import com.yiji.fintech.musfinance.center.deposit.result.*;
import com.yiji.fintech.musfinance.common.dispatcher.Dispatcher;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 充值
 * Created by ouwen@yiji.com} on 2017/5/2.
 */
@Service(version = "1.0")
public class OnlineFacadeImpl implements OnlineFacade {

    @Autowired
    private Dispatcher dispatcher;

    @Override
    public AliAppPayResult deopsitAliApp(AliAppPayFacadeOrder aliAppOrder) {
        AliAppPayResult result = new AliAppPayResult();
        initAndDispatcher(result,aliAppOrder);
        return result;
    }

    @Override
    public OfflinePayResult depositOffline(OfflinePayFacadeOrder offlineOrder) {
        OfflinePayResult result = new OfflinePayResult();
        initAndDispatcher(result,offlineOrder);
        return result;
    }

    @Override
    public OnlineResult depositForm(OnlineFacadeOrder onlineOrder) {
        OnlineResult result = new OnlineResult();
        initAndDispatcher(result,onlineOrder);
        return result;
    }

    @Override
    public ScanCodePayResult depositScanCode(ScanCodePayFacadeOrder scanCodeOrder) {
        ScanCodePayResult result = new ScanCodePayResult();
        initAndDispatcher(result,scanCodeOrder);
        return result;
    }

    @Override
    public ServiceWindowPayResult depositServiceWindow(ServiceWindowPayFacadeOrder serviceWindowOrder) {
        ServiceWindowPayResult result = new ServiceWindowPayResult();
        initAndDispatcher(result,serviceWindowOrder);
        return result;
    }

    @Override
    public WxAppPayResult depositWxApp(WxAppPayFacadeOrder wxAppOrder) {
        WxAppPayResult result = new WxAppPayResult();
        initAndDispatcher(result,wxAppOrder);
        return result;
    }

    @Override
    public WxPublicPayResult depositWxPublic(WxPublicPayFacadeOrder wxPublicOrder) {
        WxPublicPayResult result = new WxPublicPayResult();
        initAndDispatcher(result,wxPublicOrder);
        return result;
    }

    /**
     * 初始化result执行分发
     * @param result
     * @param order
     */
    private void initAndDispatcher(ResultFacade result,OrderFacade order){
        result.setStatus(ResultStatus.processing);
        result.setCode(ResultStatus.processing.code());
        result.setDetail(ResultStatus.processing.getMessage());
        dispatcher.doExcute(order,result);
    }
}
